package ac.zlf.springmybatis.core.mybatis.dialect;

import ac.zlf.springmybatis.core.mybatis.domain.PageRequest;

import org.apache.ibatis.mapping.MappedStatement;

public class PostgreSQLDialect
        extends Dialect {
    public PostgreSQLDialect(MappedStatement mappedStatement, Object parameterObject, PageRequest pageRequest) {
        super(mappedStatement, parameterObject, pageRequest);
    }

    protected String getLimitString(String sql, String offsetName, int offset, String limitName, int limit) {
        StringBuffer buffer = new StringBuffer(sql.length() + 20).append(sql);
        if (offset > 0) {
            buffer.append(" limit ? offset ?");
            setPageParameter(limitName, Integer.valueOf(limit), Integer.class);
            setPageParameter(offsetName, Integer.valueOf(offset), Integer.class);
        } else {
            buffer.append(" limit ?");
            setPageParameter(limitName, Integer.valueOf(limit), Integer.class);
        }
        return buffer.toString();
    }
}